﻿namespace System.Linq
{
	using System.Collections.Generic;
	using System.IO;

	/// <summary>
	/// Provides a set of extensions methods for strings.
	/// </summary>
	public static class StringExtensions
	{
		/// <summary>
		/// Splits a string into lines.
		/// </summary>
		/// <param name="source"></param>
		/// <returns>Returns lines as an enumerable.</returns>
		public static IEnumerable<string> SplitToLines(this string source)
		{
			if (source == null)
				throw new ArgumentNullException("source");

			using (StringReader reader = new StringReader(source))
			{
				string line = reader.ReadLine();

				while (line != null)
				{
					yield return line;
					line = reader.ReadLine();
				}
			}
		}
	}
}
